﻿Option Strict On

Imports DbDataLib
Imports KUeLib
Imports System.Data.Common

Namespace Services

    Public Class StatusDataService
        Inherits ServiceDefinitions.StatusDataService

        Public Sub New(ByVal dataService As DbDataService)
            MyBase.New(dataService)
        End Sub

        Public Overrides Function GetStatusForProcess(ByVal processName As String) As List(Of Status.Status)
            Dim cmd As DbCommand = _dataService.Factory.CreateCommand()
            Dim sb As New Text.StringBuilder
            Dim dt As DataTable

            Dim los As New List(Of Status.Status)

            sb.AppendLine("SELECT * FROM status WHERE s_vorgang = @p_vorgang")
            cmd.CommandText = sb.ToString()
            cmd.Parameters.Add(_dataService.CreateParameter("p_vorgang", DbType.String, processName))

            dt = _dataService.GetDataTable(cmd)

            For i As Integer = 0 To dt.Rows.Count - 1 Step 1
                Dim ts As New Status.Status
                ts.Bezeichnung = CStr(Utils.DbNull2Nothing(dt.Rows(i)!s_bezeichnung))
                ts.Vorgang = CStr(Utils.DbNull2Nothing(dt.Rows(i)!s_vorgang))
                los.Add(ts)
            Next

            Return los

        End Function

    End Class

End Namespace